import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HeroService } from '../../../../services/hero.service';
import { NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-tenantinfo',
  templateUrl: './tenantinfo.component.html',
  styleUrls: ['./tenantinfo.component.css']
})
export class TenantinfoComponent implements OnInit {

  public id: number;
  public radioValue: string = "1";
  public data: Array<any> = [''];
  public province: Array<any> = ['']
  public city: Array<any> = ['']
  public district: Array<any> = ['']
  public signlist: Array<any> = [];
  public printerinfo: string;
  public PageIndex: number = 1;
  public PageSize: number = 6;
  public PageTotal: number;
  constructor(private heroService: HeroService,
    private route: ActivatedRoute,
    private modalService: NzModalService) { }

  ngOnInit() {
    this.id = this.route.snapshot.params["id"];
    this.getTaskinfo(1, true);
  }

  //获取租户详情数据
  getTaskinfo(radioValue, getInfo) {
    let url1 = host + "/main/merchantConnectUser/info?id=" + this.id + "&statusArray=1&getInfo=" + getInfo + "&page=" + this.PageIndex + "&pageSize=" + this.PageSize;
    let url2 = host + "/main/merchantConnectUser/info?id=" + this.id + "&statusArray=2&statusArray=3&getInfo=" + getInfo + "&page=" + this.PageIndex + "&pageSize=" + this.PageSize;
    this.heroService.get(eval(`url${radioValue}`)).then(result => {
      if (result.code == 0) {
        if (getInfo) {
          this.data[0] = result.data.bean;
          this.province[0] = result.data.province;
          this.city[0] = result.data.city;
          this.district[0] = result.data.district;
        }
        //签约中
        if (radioValue == 1) {
          this.signlist = result.data.Compact.pageBean.result;
          this.printerinfo = result.data.Compact.printer;
          this.PageIndex = result.data.Compact.pageBean.curPage;
          this.PageTotal = result.data.Compact.pageBean.totalRow;
        }
        //已结算
        if (radioValue == 2) {
          this.signlist = result.data.Compact.pageBean.result;
          this.printerinfo = result.data.Compact.printer;
          this.PageIndex = result.data.Compact.pageBean.curPage;
          this.PageTotal = result.data.Compact.pageBean.totalRow;
        }
      } else {
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }
  //监听数据
  getRadioValue() {
    console.log(this.radioValue);
    if (this.radioValue == "1") {
      this.getTaskinfo(1, false);
    }
    if (this.radioValue == "2") {
      this.getTaskinfo(2, false);
    }
  }

  //分页
  PageIndexChange(event) {
    this.PageIndex = event;
    this.getTaskinfo(this.radioValue, false);
  }
}

